package com.lcc.myblog.service.impl;

import com.lcc.myblog.pojo.dv.BkArticleDV;
import com.lcc.myblog.pojo.dv.BkArticleDtlDV;
import com.lcc.myblog.service.BkArticleDtlService;
import com.lcc.myblog.service.BkArticleService;
import com.lcc.myblog.mapper.BkArticleMapper;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
/** 
 * 文章管理服务实现
 * @auth lcc
 * @date 2025-03-25
 */
@Service
@Transactional
@AllArgsConstructor
public class BkArticleServiceImpl implements BkArticleService {

    private BkArticleMapper mapper;
    

    @Override
    public BkArticleMapper getMapper() {
       return mapper;
    }

    private BkArticleDtlService bkArticleDtlService;

    /**
     * 保存文章, 存在更新, 不存在插入
     * @param dv
     */
    @Override
    public void save(BkArticleDV dv) {
        if(dv.getArticleId() != null){
            this.updateById(dv);
            BkArticleDtlDV dtlDV = new BkArticleDtlDV();
            dtlDV.setArticleId(dv.getArticleId());
            dtlDV.setContent(dv.getContent());
            bkArticleDtlService.updateById(dtlDV);
            return;
        }
        this.insert(dv);
        BkArticleDtlDV dtlDV = new BkArticleDtlDV();
        dtlDV.setArticleId(dv.getArticleId());
        dtlDV.setContent(dv.getContent());
        bkArticleDtlService.insert(dtlDV);
    }

}